*************** Preamble
***************
***************

***Set Stata options
clear 
cap clear matrix
cap clear mata
set more off
cap set mat 800
cap set mem 500m

***Set directories
global maindirectory C:\Users\Dropbox\Papers /*Update path to relevant working directory*/
global data $maindirectory\Data\Clean Data\
global output $maindirectory\Output\

***Output options
global outopts st(coef se pval) paren(se) br(pval) bdec(3) excel

*************** Table 3 and Section 5.2: Victory Rates
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Make log
cap log close
log using "table3_section52_victory_rates", text replace

***Benchmark 

*total number of wars between budget (1) vs non-budget (0) coalitions
count if n_war_10

*total number of wars between non-budget (0) vs budget (1) coalitions
count if n_war_01

*total number of draws in wars between budget (1) vs non-budget (0) coalitions
count if n_draw_10

*total number of draws in wars between non-budget (0) vs budget (1) coalitions
count if n_draw_01

*thus:
*excluding draws, total number of wars between budget/non-budget coalitions=(31+20)-(7+1)=43
*including draws, total number of wars between budget/non-budget coalitions=(31+20)=51

*total number of wins by side A in wars between budget (1) vs non-budget (0) coalitions
count if n_win_sideA_10

*total number of wins by side B in wars between non-budget (0) vs budget (1) coalitions
count if n_win_sideB_01

*thus, for benchmark: 
*total number of budgetary coalition wins=22+12=34
*excluding draws, budgetary coalitions won 34/43=79 percent of wars vs non-budgetary coalitions
*including draws, budgetary coalitions won 34/51=67 percent of wars vs non-budgetary coalitions

***Wars in Europe only

preserve 

drop if noneurope==1

*total number of wars between budget (1) vs non-budget (0) coalitions
count if n_war_10

*total number of wars between non-budget (0) vs budget (1) coalitions
count if n_war_01

*total number of draws in wars between budget (1) vs non-budget (0) coalitions
count if n_draw_10

*total number of draws in wars between non-budget (0) vs budget (1) coalitions
count if n_draw_01

*thus:
*excluding draws, total number of wars between budget/non-budget coalitions=(9+17)-(3+1)=22
*including draws, total number of wars between budget/non-budget coalitions=(31+20)=26

*total number of wins by side A in wars between budget (1) vs non-budget (0) coalitions
count if n_win_sideA_10

*total number of wins by side B in wars between non-budget (0) vs budget (1) coalitions
count if n_win_sideB_01

*thus, for wars in Europe only: 
*total number of budgetary coalition wins=6+10=16
*excluding draws, budgetary coalitions won 16/22=73 percent of wars vs non-budgetary coalitions
*including draws, budgetary coalitions won 16/26=62 percent of wars vs non-budgetary coalitions

restore

***Wars between non-budget (0) vs non-budget (0) coalitions

*total number of wars between non-budget (0) vs non-budget (0) coalitions
count if n_war_00

*total number of draws in wars between non-budget (0) vs non-budget (0) coalitions
count if n_draw_00

*thus:
*excluding draws, total number of wars between non-budget/non-budget coalitions=40-7=33

*total number of wins by side A in wars between non-budget (0) vs non-budget (0) coalitions
count if n_win_sideA_00

*total number of wins by side B in wars between non-budget (0) vs non-budget (0) coalitions
count if n_win_sideB_00

*thus: 
*excluding draws, side A won won 16/33=48 percent of wars between non-budgetary vs non-budgetary coalitions
*excluding draws, side B won won 17/33=52 percent of wars between non-budgetary vs non-budgetary coalitions

log close

*************** Section 5.3: Benchmark Sample and Descriptive Statistics
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Make log
cap log close
log using "section53_descriptive_stats", text replace

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

*total number of wars
count if n_war_00 | n_war_10 | n_war_01 | n_war_11

*total number of major wars
count if majorwar==1

*total number of wars in Europe
count if noneurope==0

*thus:
*excluding draws, total number of wars=82
*of which 25/82=30% were major, and 42/82=51% were fought in Europe

log close

*************** Table 4
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

cap erase table4.txt
cap erase table4.xml
	*Column 1: Benchmark
probit sideAwin logbudgetABratio, vce(robust)
		outreg2 using table4, keep(logbudgetABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 2: Add logsuffrageABratio
probit sideAwin logbudgetABratio logsuffrageABratio, vce(robust)
		outreg2 using table4, keep(logbudgetABratio logsuffrageABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 3: Add loglaborABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio, vce(robust)
		outreg2 using table4, keep(logbudgetABratio logsuffrageABratio loglaborABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 4: Add logcapitalABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using table4, keep(logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
cap erase table4.txt

*************** Table A13: Restrict Sample
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

*Restrict to sample from Table 5, Column 3
drop if sideAgdp==. | sideBgdp==.

cap erase tableA13.txt
cap erase tableA13.xml
	*Column 1: Benchmark
probit sideAwin logbudgetABratio, vce(robust)
		outreg2 using tableA13, keep(logbudgetABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 2: Add logsuffrageABratio
probit sideAwin logbudgetABratio logsuffrageABratio, vce(robust)
		outreg2 using tableA13, keep(logbudgetABratio logsuffrageABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 3: Add loglaborABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio, vce(robust)
		outreg2 using tableA13, keep(logbudgetABratio logsuffrageABratio loglaborABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 4: Add logcapitalABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using tableA13, keep(logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
cap erase tableA13.txt

*************** Table A14: Logit
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

cap erase tableA14.txt
cap erase tableA14.xml
	*Column 1: Benchmark
logit sideAwin logbudgetABratio, vce(robust)
		outreg2 using tableA14, keep(logbudgetABratio) $outopts ///
		addtext(Model, Logit, SE, Robust) append
	*Column 2: Add logsuffrageABratio
logit sideAwin logbudgetABratio logsuffrageABratio, vce(robust)
		outreg2 using tableA14, keep(logbudgetABratio logsuffrageABratio) $outopts ///
		addtext(Model, Logit, SE, Robust) append
	*Column 3: Add loglaborABratio
logit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio, vce(robust)
		outreg2 using tableA14, keep(logbudgetABratio logsuffrageABratio loglaborABratio) $outopts ///
		addtext(Model, Logit, SE, Robust) append
	*Column 4: Add logcapitalABratio
logit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using tableA14, keep(logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Logit, SE, Robust) append
cap erase tableA14.txt

*************** Table A15: Poisson
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

cap erase tableA15.txt
cap erase tableA15.xml
	*Column 1: Benchmark
poisson sideAwin logbudgetABratio, vce(robust)
		outreg2 using tableA15, keep(logbudgetABratio) $outopts ///
		addtext(Model, Poisson, SE, Robust) append
	*Column 2: Add logcapitalABratio
poisson sideAwin logbudgetABratio logsuffrageABratio, vce(robust)
		outreg2 using tableA15, keep(logbudgetABratio logsuffrageABratio) $outopts ///
		addtext(Model, Poisson, SE, Robust) append
	*Column 3: Add loglaborABratio
poisson sideAwin logbudgetABratio logsuffrageABratio loglaborABratio, vce(robust)
		outreg2 using tableA15, keep(logbudgetABratio logsuffrageABratio loglaborABratio) $outopts ///
		addtext(Model, Poisson, SE, Robust) append
	*Column 4: Add logcapitalABratio
poisson sideAwin logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using tableA15, keep(logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Poisson, SE, Robust) append
cap erase tableA15.txt

*************** Table A16: Include Draws
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

cap erase tableA16.txt
cap erase tableA16.xml
	*Column 1: Benchmark
probit sideAwin logbudgetABratio, vce(robust)
		outreg2 using tableA16, keep(logbudgetABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 2: Add logsuffrageABratio
probit sideAwin logbudgetABratio logsuffrageABratio, vce(robust)
		outreg2 using tableA16, keep(logbudgetABratio logsuffrageABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 3: Add loglaborABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio, vce(robust)
		outreg2 using tableA16, keep(logbudgetABratio logsuffrageABratio loglaborABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 4: Add logcapitalABratio
probit sideAwin logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using tableA16, keep(logbudgetABratio logsuffrageABratio loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
cap erase tableA16.txt

*************** Table A17: Raw (Unlogged) Ratios
***************
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

cap erase tableA17.txt
cap erase tableA17.xml
	*Column 1: Benchmark
probit sideAwin budgetABratio, vce(robust)
		outreg2 using tableA17, keep(budgetABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 2: Add suffrageABratio
probit sideAwin budgetABratio suffrageABratio, vce(robust)
		outreg2 using tableA17, keep(budgetABratio suffrageABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 3: Add laborABratio
probit sideAwin budgetABratio suffrageABratio laborABratio, vce(robust)
		outreg2 using tableA17, keep(budgetABratio suffrageABratio laborABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 4: Add capitalABratio
probit sideAwin budgetABratio suffrageABratio laborABratio capitalABratio, vce(robust)
		outreg2 using tableA17, keep(budgetABratio suffrageABratio laborABratio capitalABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
cap erase tableA17.txt

*************** Table A18: Weighted Budgetary and Suffrage Variables 
*************** 
***************
*Load data
cd "$data"
use "cd_victory_crosssection_jop", clear
cd "$output"

*Exclude draws
drop if n_draw_00==1 | n_draw_10==1 | n_draw_01==1 | n_draw_11==1

cap erase tableA18.txt
cap erase tableA18.xml
	*Column 1: Benchmark
probit sideAwin logbudgetABratio_weighted, vce(robust)
		outreg2 using tableA18, keep(logbudgetABratio_weighted) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 2: Add logsuffrageABratio
probit sideAwin logbudgetABratio_weighted logsuffrageABratio_weighted, vce(robust)
		outreg2 using tableA18, keep(logbudgetABratio_weighted logsuffrageABratio_weighted) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 3: Add loglaborABratio
probit sideAwin logbudgetABratio_weighted logsuffrageABratio_weighted loglaborABratio, vce(robust)
		outreg2 using tableA18, keep(logbudgetABratio_weighted logsuffrageABratio_weighted loglaborABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
	*Column 4: Add logcapitalABratio
probit sideAwin logbudgetABratio_weighted logsuffrageABratio_weighted loglaborABratio logcapitalABratio, vce(robust)
		outreg2 using tableA18, keep(logbudgetABratio_weighted logsuffrageABratio_weighted loglaborABratio logcapitalABratio) $outopts ///
		addtext(Model, Probit, SE, Robust) append
cap erase tableA18.txt
